package com.demo.demo.itext7.page;

import com.itextpdf.io.font.PdfEncodings;
import com.itextpdf.io.image.ImageDataFactory;
import com.itextpdf.kernel.colors.Color;
import com.itextpdf.kernel.colors.DeviceRgb;
import com.itextpdf.kernel.events.Event;
import com.itextpdf.kernel.events.IEventHandler;
import com.itextpdf.kernel.events.PdfDocumentEvent;
import com.itextpdf.kernel.font.PdfFont;
import com.itextpdf.kernel.font.PdfFontFactory;
import com.itextpdf.kernel.geom.Rectangle;
import com.itextpdf.kernel.pdf.PdfDocument;
import com.itextpdf.kernel.pdf.PdfPage;
import com.itextpdf.kernel.pdf.canvas.PdfCanvas;
import com.itextpdf.kernel.pdf.xobject.PdfFormXObject;
import com.itextpdf.layout.Canvas;
import com.itextpdf.layout.Document;
import com.itextpdf.layout.borders.Border;
import com.itextpdf.layout.element.Cell;
import com.itextpdf.layout.element.Image;
import com.itextpdf.layout.element.Paragraph;
import com.itextpdf.layout.element.Tab;
import com.itextpdf.layout.element.TabStop;
import com.itextpdf.layout.element.Table;
import com.itextpdf.layout.property.HorizontalAlignment;
import com.itextpdf.layout.property.TabAlignment;
import com.itextpdf.layout.property.TextAlignment;
import com.itextpdf.layout.property.VerticalAlignment;
import com.itextpdf.text.Font;
import com.itextpdf.text.PageSize;
import java.io.IOException;
import java.net.MalformedURLException;

/**
 * Created by kdl on 2018/9/3.
 */
public class FooterEventHandler implements IEventHandler {

  /*  private PdfFont font=null;

    public FooterEventHandler(PdfFont font) {
        this.font = font;
    }*/

    @Override
    public void handleEvent(final Event event) {
        PdfFont font2 = null;
        try {
            font2 = PdfFontFactory.createFont("D:\\font\\MYingHei.ttf", PdfEncodings.IDENTITY_H, true);
        } catch (IOException e) {
            e.printStackTrace();
        }
        PdfDocumentEvent docEvent = (PdfDocumentEvent) event;
        PdfDocument pdf = docEvent.getDocument();
        PdfPage page = docEvent.getPage();
        Rectangle pageSize = page.getPageSize();

        PdfCanvas pdfCanvas = new PdfCanvas(
                page.getLastContentStream(), page.getResources(), pdf);
        Canvas canvas = new Canvas(pdfCanvas, pdf, pageSize);


        float x =  pageSize.getLeft()+60;
        float y =  pageSize.getTop()-50;
        float x2 =  pageSize.getRight()-570;
        float y2 =  pageSize.getTop()-820;

        canvas.setFontSize(7f);
        try {
            Paragraph p2 =  new Paragraph();
            p2.setFont(font2);
           // p2.setFont(font);
            p2.add("Fusion Bank Limited 富融銀行有限公司\n ");
            p2.add("Bank Address : Unit 201-212 InnoCentre, 72 Tat Chee Avenue, Kowloon Tong, Kowloon, H.K.\n");
            p2.add("銀行地址 : 九龍塘達之路72號創新中心2樓201-212室\n");
            p2.add("Customer Service Hotline 客戶服務熱線: +852 2111 2688\n");
            //p2.add("80000088888\n");
            canvas.showTextAligned(p2, x2, y2, TextAlignment.LEFT);

            canvas.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }



}
